/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fuzzyLogic;

/**
 *
 * @author CygiDawid
 */
public class VariableTriangle extends VariableSet {
    private final double _mid;/*
    private final double[] _function1;
    private final double[] _function2;*/
    private final double _divider1; // mianowniki podczas obliczania przynależności do zbiorów
    private final double _divider2;
    
    
    public VariableTriangle(String name, double from, double mid, double to, double step) {
        super(name, from, to, step);
        /*
        _function1 = getFunction(from, 0d, mid, 1d);
        _function2 = getFunction(mid, 1d, to, 1d);*/
        
        _mid = mid;
        
        _divider1 = 1d / (_mid - _from);
        _divider2 = 1d / (_to - _mid);
        createSet();
    }
    
    /*
    @Override
    public double getAffiliation(double value) {/*
        if (isOut(value)) {
            return 0d;
        }
        
        if (value < _mid) {
            return _function1[0] * value + _function1[1];
        }
        
        return _function2[0] * value + _function2[1];
        
        
    }*/
    
    @Override
    protected double calcValue(double value) {
        double result = 0d;
        
        if (value > _from && value <= _mid) {
            result = (value - _from) * _divider1;
        }
        else if (value > _mid && value < _to) {
            result = (_to - value) * _divider2;
        }
        
        return result;
    }
}
